﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi.wMall.Public
{
	public partial class wfForumList : msBsc.Cls.BPage
	{
		protected void Page_Load(object sender, EventArgs e)
		{

		}

        string countryId = "";
        string cityId = "";
        string destionId = "";
        private void getArea2(string parentsId)
        {
            if (string.IsNullOrEmpty(parentsId))
            {
                return;
            }
            using (msBsc.AppLogic.DataAlc.CBizCountryCity cbcc = new AppLogic.DataAlc.CBizCountryCity())
            {
                DataSet ds = cbcc.SelectCountryByParentId(parentsId);
                if (ds==null||ds.Tables[0].Rows.Count<1)
                {
                    return;
                }
                DataRow dr = ds.Tables[0].NewRow();
                dr["COUNTRY_CITY_ID"] = "";
                dr["COUNTRY_CITY_NME"] = "全部";
                ds.Tables[0].Rows.InsertAt(dr, 0);
                cityId = this.GetParamHtValue("cityId");
                string ret = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 1000, "");
                if (string.IsNullOrEmpty(cityId))
                {
                    cityId = ds.Tables[0].Rows[0]["COUNTRY_CITY_ID"].ToString();
                }
                this.ExecJScript(@"updateSelet(""cityId_select""," + ret + @",""" + cityId + @""")");
                getArea3(cityId);
            }
        }
        private void getArea3(string parentsId)
        {
            if (string.IsNullOrEmpty(parentsId))
            {
                return;
            }
            using (msBsc.AppLogic.DataAlc.CBizCountryCity cbcc = new AppLogic.DataAlc.CBizCountryCity())
            {
                DataSet ds = cbcc.SelectCountryByParentId(parentsId);
                //string isAll = this.GetParamHtValue("isAll");
                //if (isAll.ToLower() == "true")
                //{
                //    DataRow dr = ds.Tables[0].NewRow();
                //    dr["COUNTRY_CITY_ID"] = "";
                //    dr["COUNTRY_CITY_NME"] = "全部";
                //    ds.Tables[0].Rows.InsertAt(dr, 0);
                //}
                DataRow dr = ds.Tables[0].NewRow();
                dr["COUNTRY_CITY_ID"] = "";
                dr["COUNTRY_CITY_NME"] = "全部";
                ds.Tables[0].Rows.InsertAt(dr, 0);
                string ret = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 1000, "");
                destionId = this.GetParamHtValue("destionId");
                if (string.IsNullOrEmpty(destionId))
                {
                    destionId = ds.Tables[0].Rows[0]["COUNTRY_CITY_ID"].ToString();
                }
                this.ExecJScript(@"updateSelet(""destionId_select""," + ret + @",""" + destionId + @""")");

            }
        }
        private void initplace(string parentsId)
        {
            using (msBsc.AppLogic.DataAlc.CBizCountryCity cbcc = new AppLogic.DataAlc.CBizCountryCity())
            {
                DataSet ds = cbcc.SelectCountryByParentId(parentsId);
                countryId = this.GetParamHtValue("countryId");
                DataRow dr = ds.Tables[0].NewRow();
                dr["COUNTRY_CITY_ID"] = "";
                dr["COUNTRY_CITY_NME"] = "全部";
                ds.Tables[0].Rows.InsertAt(dr, 0);
                if (string.IsNullOrEmpty(countryId))
                {
                    countryId = ds.Tables[0].Rows[0]["COUNTRY_CITY_ID"].ToString();
                }
                string ret = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 1000, "");
                this.ExecJScript(@"updateSelet(""countryId_select""," + ret + @",""" + countryId + @""")");
                getArea2(countryId);
            }
        }

        private void getForumList()
        {
            string pIndex = this.GetParamHtValue("pIndex");
            string pRows = this.GetParamHtValue("pRows");
            string postsKey = this.GetParamHtValue("postsKey");
            using (msBsc.AppLogic.DataAlc.CBizSourcePosts sourcePosts = new AppLogic.DataAlc.CBizSourcePosts())
            {
                int pageIndex = 1;
                int pageRows = 10;
                int.TryParse(pIndex, out pageIndex);
                int.TryParse(pRows, out pageRows);
                DataSet ds = sourcePosts.GetVehicleForPageview(pageRows, pageIndex, "",destionId,cityId,countryId,postsKey);
                if (ds == null || ds.Tables[0].Rows.Count < 1)
                {
                    return;
                }
                string retJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 1000, "");
                this.ExecJScript(@"
                            var _html = $('#svc_list_temp').html();

                            laytpl(_html).render(" + retJson + @", function (render) {
                                $('#forumInfo').html(render);
                            });jsPage('divPage', " + Convert.ToInt32(ds.Tables[0].Rows[0]["ROWSCOUNT"].ToString()) + ", " + pageRows + ", " + pageIndex + ", 'goPage');$('#s_number').text('" + ds.Tables[0].Rows[0]["ROWSCOUNT"] + "')");
            }
        }

        public override void DoAction()
        {
            if (this.strAction == "init")
            {
                string parentsId = this.GetParamHtValue("parentsId");
                initplace(parentsId);
                getForumList();
                base.DoAction();
            }
            if (this.strAction == "gopage")
            {
                getForumList();
            }
        }
	}
}